﻿
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WindowsInput;
using WCintiqHID;
using System.Xml;
using System.Xml.Serialization;
using Treblotto_TabletDefs;
using System.IO;
using System.IO.IsolatedStorage;
using System.Windows.Controls;
using System.Windows.Input;
using System.Collections.ObjectModel;
using System.Runtime.Serialization;

///Things to think about:
///Am I storing the Key Action?
///Am I storing the entire class that and telling it to do it's thing?
///Am I Using this design in the same way that I'm storing it?




// Uses InputSimulator 0.1.0.0
// InputSimulator is a C# SendInput Wrapper

namespace TTIServer
{

	[Serializable]
	public class ExpressKeyAction
	{



		public int Id;

		public string ActionType;

		public string ActionDescription;

		public ExpressKeyAction()
		{



		}

	}


	[Serializable]
	public  class TouchPadRingAction
	{

		public int Id;

		public string ActionName;

		public string ActionDescription;

	}





	[Serializable]
	public  class ExpressKeyButtonID
	{


		public int ExpressKeyID;

		public string Name;

	}




	[Serializable]
	public  class GlobalEKSetting
	{


		public int Id;

		public int TabletID;

		public int EKID;

		public int ActionID;

		public object ActionData;

		public string ActionDescription;

		public bool Ctrl;

		public bool Alt;

		public bool Shift;

	}


	public class ExpressKeyMenuSelection : ContextMenu
	{


		MenuItem MouseClickMenuItem;
		MenuItem MouseClicks;
		MenuItem PenSpecific;
		MenuItem Shortcuts;
		MenuItem Navigation;
		MenuItem ShellRelated;
		MenuItem DisplayRelated;
		MenuItem TabletPCRelated;
		MenuItem MiscRelated;

		TabletSettings TabletSettingsRef;

		public Treblotto_TabletDefs.ExpressKeyVals.WhichSide EKSide;
		public Treblotto_TabletDefs.ExpressKeyVals.ExpressKeys WhichEK;

		public static RoutedUICommand ClickSelected = new RoutedUICommand();
		public static RoutedUICommand OpenRotationWindow = new RoutedUICommand();
		public static RoutedUICommand OpenKeyStrokeDialog = new RoutedUICommand();
		public static RoutedUICommand OpenApplicationExecuteDialog = new RoutedUICommand();
		public ExpressKeyMenuSelection( TabletSettings inTabletSettingsRef )
		{

			TabletSettingsRef = inTabletSettingsRef;

			CommandBinding customCommandBinding = new CommandBinding(ClickSelected, ExecutedCustomCommand, CanExecuteCustomCommand);
			CommandBinding rotationMenuCommandBinding = new CommandBinding(OpenRotationWindow, ExecutedRotationCommand, CanExecuteCustomCommand);
			CommandBinding KeystrokeMenuCommandBinding = new CommandBinding(OpenKeyStrokeDialog, ExecuteOpenKeystrokeDialog, CanExecuteCustomCommand);
			// attach CommandBinding to root window 
			this.CommandBindings.Add(customCommandBinding);
			this.CommandBindings.Add(rotationMenuCommandBinding);
			this.CommandBindings.Add(KeystrokeMenuCommandBinding);
			//this.CommandBindings.Add(new CommandBinding(ApplicationCommands.

			MouseClickMenuItem = new MenuItem();

			/////////////////////////
			//Add Mouse Clicks
			/////////////////////////
			MouseClickMenuItem.Header = "Mouse Clicks";
			ClickSelected.Text = "selectedMouseClick";
			

			MouseClicks = new MenuItem();
			MouseClicks.Header = "Left Click";
			MouseClicks.CommandParameter = "Left";
			MouseClicks.Command = ClickSelected;
			MouseClickMenuItem.Items.Add(MouseClicks);

			MouseClicks = new MenuItem();
			MouseClicks.Header = "Right Click";
			MouseClicks.Command = ClickSelected;
			MouseClicks.CommandParameter = "Right";
			MouseClickMenuItem.Items.Add(MouseClicks);

			MouseClicks = new MenuItem();
			MouseClicks.Header = "Middle Click";
			MouseClicks.Command = ClickSelected;
			MouseClicks.CommandParameter = "Middle";
			MouseClickMenuItem.Items.Add(MouseClicks);

			MouseClicks = new MenuItem();
			MouseClicks.Header = "Button 4 Click";
			MouseClicks.Command = ClickSelected;
			MouseClicks.CommandParameter = "Four";
			MouseClickMenuItem.Items.Add(MouseClicks);

			MouseClicks = new MenuItem();
			MouseClicks.Header = "Button 5 Click";
			MouseClicks.Command = ClickSelected;
			MouseClicks.CommandParameter = "Five";
			MouseClickMenuItem.Items.Add(MouseClicks);

			this.Items.Add(MouseClickMenuItem);

			this.Items.Add(new Separator());
			
			///////////////////////////
			// Add Shortcut Options
			///////////////////////////

			Shortcuts = new MenuItem();
			Shortcuts.Header = "Keystroke";
			OpenKeyStrokeDialog.Text = "doKeystrokDialog";
			Shortcuts.Command = OpenKeyStrokeDialog;
			this.Items.Add(Shortcuts);

			//------------------------

			Shortcuts = new MenuItem();
			Shortcuts.Header = "Modifier";

			MenuItem ModifierShortcut = new MenuItem();
			ModifierShortcut.Header = "Ctrl";
			Shortcuts.Items.Add(ModifierShortcut);

			ModifierShortcut = new MenuItem();
			ModifierShortcut.Header = "Shift";
			Shortcuts.Items.Add(ModifierShortcut);

			ModifierShortcut = new MenuItem();
			ModifierShortcut.Header = "Alt";
			Shortcuts.Items.Add(ModifierShortcut);
			this.Items.Add(Shortcuts);

			
			//-------------------------

			Shortcuts = new MenuItem();
			Shortcuts.Header = "Rotation Menu";
			OpenRotationWindow.Text = "doRotationMenu";
			Shortcuts.Command = OpenRotationWindow;
			
			
			this.Items.Add(Shortcuts);
			this.Items.Add(new Separator());

			///////////////////////////
			// Navigation
			///////////////////////////

			Navigation = new MenuItem();
			Navigation.Header = "Back";
			this.Items.Add(Navigation);

			//-------------------------

			Navigation = new MenuItem();
			Navigation.Header = "Forward";
			this.Items.Add(Navigation);

			//-------------------------

			Navigation = new MenuItem();
			Navigation.Header = "Pan/Scroll";
			this.Items.Add(Navigation);

			

			//////////////////////////
			//  Shell Related
			//////////////////////////

			ShellRelated = new MenuItem();
			ShellRelated.Header = "Open Doc/Launch App";
			this.Items.Add(ShellRelated);
			this.Items.Add(new Separator());
			

			//////////////////////////
			//	Display Related
			//////////////////////////

			DisplayRelated = new MenuItem();
			DisplayRelated.Header = "Pan & Scan Enable/Disable";
			this.Items.Add(DisplayRelated);
			this.Items.Add(new Separator());

			//////////////////////////
			//	TabletPC Related
			//////////////////////////

			TabletPCRelated = new MenuItem();
			TabletPCRelated.Header = "Tablet PC Input Panel (TIP)";
			this.Items.Add(TabletPCRelated);

			//------------------------

			TabletPCRelated = new MenuItem();
			TabletPCRelated.Header = "On Screen Keyboard";
			this.Items.Add(TabletPCRelated);

			//------------------------

			TabletPCRelated = new MenuItem();
			TabletPCRelated.Header = "TTI Music Note Input Panel";
			this.Items.Add(TabletPCRelated);



		}

		// CanExecuteRoutedEventHandler that only returns true if 
		// the source is a control. 
		private void CanExecuteCustomCommand(object sender, CanExecuteRoutedEventArgs e)
		{
			Control target = e.Source as Control;

			if (target != null)
			{
				e.CanExecute = true;
			}
			else
			{
				e.CanExecute = false;
			}
		}

		private void ExecutedCustomCommand(object sender, ExecutedRoutedEventArgs e)
		{
			RoutedUICommand inCmd = (RoutedUICommand)e.Command;
			MenuItem myMenuItem = (MenuItem)e.Source;

				Console.WriteLine("The Command {0} was sent from {1} with a parameter of {2}",inCmd.Text,myMenuItem.Header, e.Parameter);


		}

		private void ExecutedRotationCommand(object sender, ExecutedRoutedEventArgs e)
		{
			RoutedUICommand inCmd = (RoutedUICommand)e.Command;

			Console.WriteLine(inCmd.Text);


		}

		private void ExecuteOpenKeystrokeDialog(object sender, ExecutedRoutedEventArgs e)
		{
			RoutedUICommand inCmd = (RoutedUICommand)e.Command;
			ContextMenu clickedMenu = (ContextMenu)sender;

			

			Console.WriteLine(inCmd.Text);
			
			TTIServer.TTISettings.EditPresets myEP = new TTISettings.EditPresets( TabletSettingsRef, 0, 0);
			myEP.Show();


		}


	}
	
	[Serializable]
     public class ExpressKeySettings
     {
		const byte DTK2100 = 0xCC;
		const byte DTK2400 = 0xF8;
		const ushort DTK2200 = 0xD22; //????
		const ushort DTK1300 = 0xD13;
		const byte  PTK840 = 0xBA;
		const byte  PTK440 = 0XB8;
		const byte  PTH450 = 0x26;
		const byte  PTZ430 = 0x12;

		const byte numExpressGroups = 4;

		//Array of ExpressKeys
		public ExpressKey[] IntuosExpressKeys;
		
		public ExpressPadGroup[] IntuosTG;

		
		public ExpressKey[,] TabletEKs;
		
		
		public ExpressPadGroup[,] TabletEPGs;

		
		public RotationGroup TabletAPRGs;  //These Rotation Groups can be used for the touch ring too

		private List<ExpressKeyAction> AvailableActions;
		private List<TouchPadRingAction> AvailableTouchOptions;
		private List<ExpressKeyButtonID> AvailableEKButtons;

		[NonSerialized]
		IOrderedQueryable<TTIServer.T3DC.ExpressKeyAction> AvailActions;

		[NonSerialized]
		TTIServer.T3DC.TreblottoDigitizerDataDataContext theTD3C;

		private int numOfSides = 2;




		public void WriteExpressKeySettings()
		{
			//IsolatedStorageFile TTIStorage = IsolatedStorageFile.GetUserStoreForAssembly();
			//IFormatter formatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();

			//IsolatedStorageFileStream TTIFS = new IsolatedStorageFileStream("TTIAvailEKAStore", System.IO.FileMode.Create, TTIStorage);
			//formatter.Serialize(TTIFS, AvailableActions);
			//TTIFS.Close();

			//TTIFS = new IsolatedStorageFileStream("TTITabletEKs", System.IO.FileMode.Create, TTIStorage);
			//formatter.Serialize(TTIFS, TabletEKs);
			//TTIFS.Close();

			//TTIFS = new IsolatedStorageFileStream("TTITabletEPGs", System.IO.FileMode.Create, TTIStorage);
			//formatter.Serialize(TTIFS, TabletEPGs);
			//TTIFS.Close();

			//TTIFS = new IsolatedStorageFileStream("TTITabletARPGs", System.IO.FileMode.Create, TTIStorage);
			//formatter.Serialize(TTIFS, TabletAPRGs);
			//TTIFS.Close();

				//formatter.Serialize(inTTIStream, TabletEKs);
			


		}

		public void ReadExpressKeySettings()
		{

			//IsolatedStorageFile TTIStorage = IsolatedStorageFile.GetUserStoreForAssembly();
			//IFormatter formatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();

			//IsolatedStorageFileStream TTIFS = new IsolatedStorageFileStream("TTIAvailEKAStore", System.IO.FileMode.Open, TTIStorage);
			//AvailableActions = (List<ExpressKeyAction>)formatter.Deserialize(TTIFS);
			//TTIFS.Close();

			//TTIFS = new IsolatedStorageFileStream("TTITabletEKs", System.IO.FileMode.Open, TTIStorage);
			//TabletEKs = (ExpressKey[,])formatter.Deserialize(TTIFS);
			//TTIFS.Close();

			//TTIFS = new IsolatedStorageFileStream("TTITabletEPGs", System.IO.FileMode.Open, TTIStorage);
			//TabletEPGs = (ExpressPadGroup[,])formatter.Deserialize(TTIFS);
			//TTIFS.Close();

			//TTIFS = new IsolatedStorageFileStream("TTITabletARPGs", System.IO.FileMode.Open, TTIStorage);
			//TabletAPRGs = (RotationGroup)formatter.Deserialize(TTIFS);
			//TTIFS.Close();

		}


          public ExpressKeySettings()
          {

          }

		//public ExpressKeySettings(TTIServer.T3DC.TreblottoDigitizerDataDataContext inTD3C)
		//{

		//	//theTD3C = inTD3C;
		//	////IOrderedQueryable<ExpressKeyAction>
		//	//AvailActions = from AvailAct in theTD3C.ExpressKeyActions
		//	//										orderby AvailAct.Id
		//	//										 select AvailAct;

		//	//AvailableActions = new List<ExpressKeyAction>();

		//	//foreach (TTIServer.T3DC.ExpressKeyAction AAct in AvailActions)
		//	//{

		//	//	ExpressKeyAction newEKA = new ExpressKeyAction();
		//	//	newEKA.Id = AAct.Id;
		//	//	newEKA.ActionType = AAct.ActionType;
		//	//	newEKA.ActionDescription = AAct.ActionDescription;
		//	//	AvailableActions.Add(newEKA);


		//	//}

			

		//	//Stream from the File
			
		//	//AvailActions = from AvailAct in theTD3C.ExpressKeyActions
		//	//			orderby AvailAct.Id
		//	//			select AvailAct;



		//}

		public ExpressKeySettings (ushort PID)
		{

			switch (PID)
			{
				case DTK2100:
				case DTK2200:
				case DTK2400:
					numOfSides = 2;
					break;

				case DTK1300:
				case PTK840:
				case PTK440:
				case PTH450:
					numOfSides = 1;
					break;
			}


		}



		public void changeExpressKeySetting( ExpressKeyVals.WhichSide whichSide, ExpressKeyVals.ExpressKeys whichKey, ExpressKey newSettingObject)
		{
			int ws = (int)whichSide, wk = (int)Treblotto_TabletDefs.ExpressKeyVals.ButtonValue(whichKey);
			TabletEKs[ws, wk] = newSettingObject;

		}

		public class ExpressKeyActionItems : ObservableCollection<ExpressKeyAction>
		{
			public ExpressKeyActionItems(IOrderedQueryable<ExpressKeyAction> AvailActions)
				: base()
			{
				foreach (ExpressKeyAction myAction in AvailActions)
				{

					Add(myAction);

				}


			}


	
		}

		public List<ExpressKeyAction> GetActionItems()
		{
			List<ExpressKeyAction> retList = new List<ExpressKeyAction>();

			foreach (ExpressKeyAction myAction in AvailableActions)
				retList.Add(myAction);

			return retList;
		}

          //Array of values for the LED indicators.
          public byte[] CintiqLEDs;

          //DeviceIOControl SetLEDs


          public class ToggleButtonAction
          {

          }

		[Serializable]
          public enum ExpressKeyActionType
          {
               Keystroke = 1,
			MouseClick,
			Run,
			Toggle,
			Momentary,
			MIDI,
			SpecialFunction,
			ExpressGroup,
			RotationMenu
		 };

		[Serializable]
          public enum ExpressPadGroupActionType
          {
               Scroll,
               Keystroke,
               MIDI,
               ValueLoop
          }




		[Serializable]
          public class RotationStopValue
          {

               private string RotationStopLabel;
               private ExpressKeyActionType StopAction;
               private WindowsInput.VirtualKeyCode[] KeyCombo;

               public RotationStopValue(string Label, ExpressKeyActionType RotateAction, WindowsInput.VirtualKeyCode[] vKC)
               {

                    RotationStopLabel = Label;
                    StopAction = RotateAction;
                    KeyCombo = new WindowsInput.VirtualKeyCode[vKC.Length];
				for (int i = 0; i < vKC.Length; i++)
					KeyCombo[i] = vKC[i];

               }



			public WindowsInput.VirtualKeyCode[] GetActionValue()
			{

				return KeyCombo;

			}

          }

		[Serializable]
          public class ExpressKey 
          {

               public ExpressKey( string Label, ExpressKeyActionType ekat, WindowsInput.VirtualKeyCode[] vKC, int KeyCodeSize )
               {
                    ExpressKeyLabel = Label;
                    EKAction = ekat;
                    KeyCombo = new WindowsInput.VirtualKeyCode[KeyCodeSize];
                    Array.Copy(vKC, KeyCombo, KeyCodeSize);
               }

			public ExpressKey(string Label, ExpressKeyActionType ekat, byte[] Data, int arraySize)
			{
				ExpressKeyLabel = Label;
				EKAction = ekat;
				MomentaryData = new byte[arraySize];
				Array.Copy(Data, MomentaryData, arraySize);
			}

			public ExpressKey(String Label, ExpressKeyActionType ekat)
			{

				ExpressKeyLabel = Label;
				EKAction = ekat;


			}


               public string ExpressKeyLabel;
               //{
               //     get { return ExpressKeyLabel; }
               //     set { ExpressKeyLabel = value; }
               //}

               public ExpressKeyActionType EKAction;
               //{
               //     get { return EKAction; }
               //     set { EKAction = value; }
               //}

               public String Path;
               //{
               //     get { return Path; }
               //     set { Path = value; }
               //}

               public WindowsInput.VirtualKeyCode[] KeyCombo;
               public byte[] MouseClick;
               public byte[] MIDICmdData;
			public byte[] MomentaryData;
			public byte[] ToggleData;

          }

		[Serializable]
          public class ExpressPadGroup
          {
               //Constructor for Scroll ExpressGroups
               public ExpressPadGroup()
               {
                    EPGroupLabel = "Vertical Scroll";
                    EPGAction = ExpressPadGroupActionType.Scroll;
               }

               public ExpressPadGroup(string epgLabel, ExpressPadGroupActionType epgAction, VirtualKeyCode[] vksUp, VirtualKeyCode[] vksDn)
               {
                    EPGroupLabel = epgLabel;
                    EPGAction = epgAction;
                    KeystrokeDn = new VirtualKeyCode[vksDn.Length];
                    vksDn.CopyTo(KeystrokeDn, 0);

                    KeystrokeUp = new VirtualKeyCode[vksUp.Length];
                    vksUp.CopyTo(KeystrokeUp, 0);
               }


               public String EPGroupLabel;
               public ExpressPadGroupActionType EPGAction;
               public WindowsInput.VirtualKeyCode[] KeystrokeUp;
               public WindowsInput.VirtualKeyCode[] KeystrokeDn;
               public byte[] MIDICmdDataUp;
               public byte[] MIDICmdDataDn;

               
          }

		[Serializable]
          public class RotationGroup  //Press Group Button and Rotate Pen to change group
          {

               private int currentLoc;
               private int NumberOfValues;
               private RotationStopValue[] RotationValuesLoop;

               public RotationGroup()
               {
                    string Label;
                    WindowsInput.VirtualKeyCode[] myVKC;
                    NumberOfValues = 6;
                    currentLoc = 0;
                    RotationValuesLoop = new RotationStopValue[NumberOfValues];


                    Label = "32nd Note";
                    myVKC = new VirtualKeyCode[1];
                    myVKC[0] = VirtualKeyCode.NUMPAD1;
                    RotationValuesLoop[0] = new RotationStopValue(Label, ExpressKeyActionType.Keystroke, myVKC);

                    Label = "16th Note";
                    myVKC = new VirtualKeyCode[1];
                    myVKC[0] = VirtualKeyCode.NUMPAD2;
                    RotationValuesLoop[1] = new RotationStopValue(Label, ExpressKeyActionType.Keystroke, myVKC);

                    Label = "Eighth Note";
                    myVKC = new VirtualKeyCode[1];
                    myVKC[0] = VirtualKeyCode.NUMPAD3;
                    RotationValuesLoop[2] = new RotationStopValue(Label, ExpressKeyActionType.Keystroke, myVKC);

                    Label = "Quarter Note";
                    myVKC = new VirtualKeyCode[1];
                    myVKC[0] = VirtualKeyCode.NUMPAD4;
                    RotationValuesLoop[3] = new RotationStopValue(Label, ExpressKeyActionType.Keystroke, myVKC);

                    Label = "Half Note";
                    myVKC = new VirtualKeyCode[1];
                    myVKC[0] = VirtualKeyCode.NUMPAD5;
                    RotationValuesLoop[4] = new RotationStopValue(Label, ExpressKeyActionType.Keystroke, myVKC);

                    Label = "Whole Note";
                    myVKC = new VirtualKeyCode[1];
                    myVKC[0] = VirtualKeyCode.NUMPAD6;
                    RotationValuesLoop[5] = new RotationStopValue(Label, ExpressKeyActionType.Keystroke, myVKC);



               }

               public int LocInc()
               {
                    currentLoc++;

                    if (currentLoc == NumberOfValues)
                         currentLoc = 0;

                    return currentLoc;

               }


               public int LocDec()
               {
                    currentLoc--;

                    if (currentLoc < 0)
                         currentLoc = NumberOfValues-1;

                    return currentLoc;

               }

               public RotationStopValue GetCurrentAction()
               {

                    return RotationValuesLoop[currentLoc];

               }

          }

		public void launchTIP()
		{
			var path = Environment.GetFolderPath(Environment.SpecialFolder.CommonProgramFiles) + @"\Microsoft Shared\ink\TabTip.exe";

			if (!File.Exists(path))
			{
				// older windows versions
				path = Environment.GetFolderPath(Environment.SpecialFolder.System) + @"\osk.exe";
			}

		}

          public bool Initialize( bool LoadFromFile, int NumExpressKeys = 9, int NumSides = 2)
          {


               int Left = (int)ExpressKeyVals.WhichSide.Left;
			int Right = (int)ExpressKeyVals.WhichSide.Right;

			TabletEKs = new ExpressKey[NumSides, NumExpressKeys];
			TabletEPGs = new ExpressPadGroup[numOfSides,numExpressGroups];
			TabletAPRGs = new RotationGroup();


               if (LoadFromFile)
               {
				ReadExpressKeySettings();
				#region Database access code
				//VirtualKeyCode[] vks;
				//byte[] MomentaryDatar;
				//IEnumerable<TTIServer.T3DC.GlobalEKSetting> ExpressKeyGlobalSettings = from GEKS in theTD3C.GlobalEKSettings
				//														 select GEKS;

				//foreach (TTIServer.T3DC.GlobalEKSetting GEKS in ExpressKeyGlobalSettings)
				//{
				//	int numVKs = 0, i = 0;

				//	int pos = GEKS.ExpressKeyButtonID.ExpressKeyID % 10;
				//	int side = GEKS.ExpressKeyButtonID.ExpressKeyID / 10;


				//	switch (GEKS.ActionID)
				//	{
				//		case 1: //Keystroke;
				//			int iActionData = int.Parse((string)GEKS.ActionData);

				//			if (iActionData > 0)
				//				numVKs++;
				//			if (GEKS.Alt)
				//				numVKs++;
				//			if (GEKS.Shift)
				//				numVKs++;
				//			if (GEKS.Ctrl)
				//				numVKs++;

				//			vks = new VirtualKeyCode[numVKs];
				//			if (GEKS.Alt)
				//			{
				//				vks[i] = VirtualKeyCode.MENU;
				//				i++;
				//			}
				//			if (GEKS.Shift)
				//			{
				//				vks[i] = VirtualKeyCode.SHIFT;
				//				i++;
				//			}
				//			if (GEKS.Ctrl)
				//			{
				//				vks[i] = VirtualKeyCode.CONTROL;
				//				i++;
				//			}
				//			if (iActionData > 0)
				//			{
				//				vks[i] = (VirtualKeyCode)iActionData;
				//				i++;
				//			}

				//			//int pos = GEKS.ExpressKeyButtonID.ExpressKeyID % 10;
				//			//int side = GEKS.ExpressKeyButtonID.ExpressKeyID  / 10;



				//			TabletEKs[Left, pos - 1] = new ExpressKey(GEKS.ActionDescription, (ExpressKeyActionType)GEKS.ActionID, vks, i);
				//			TabletEKs[Right, pos - 1] = new ExpressKey(GEKS.ActionDescription, (ExpressKeyActionType)GEKS.ActionID, vks, i);

				//			break;
				//		case 2:
				//			break;
				//		case 3:
				//			break;
				//		case 4:
				//			break;
				//		case 5:
				//			break;
				//		case 6:
				//			break;
				//		case 7:
				//			break;
				//		case 8:	//Express Group Button
				//			TabletEKs[Left, pos - 1] = new ExpressKey(GEKS.ActionDescription, (ExpressKeyActionType)GEKS.ActionID);
				//			TabletEKs[Right, pos - 1] = new ExpressKey(GEKS.ActionDescription, (ExpressKeyActionType)GEKS.ActionID);

				//			break;


				//	}



				//}
				#endregion

				return true;
               }
               else
               {



                    VirtualKeyCode[] vks;
				    byte[] MomentaryDatar;

                    //EK1
                    vks = new VirtualKeyCode[1];
				vks[0] = 0;
                    TabletEKs[Left, 0] = new ExpressKey("Select Express Group", ExpressKeyActionType.ExpressGroup, vks, 0);
				TabletEKs[Right, 0] = new ExpressKey("Select Express Group", ExpressKeyActionType.ExpressGroup, vks, 0);

                    //EK2
                    vks = new VirtualKeyCode[2];
                    vks[0] = VirtualKeyCode.CONTROL;
                    vks[1] = VirtualKeyCode.F13;
                    TabletEKs[Left, 1] = new ExpressKey("Rotate Left", ExpressKeyActionType.Keystroke, vks, 2);
				TabletEKs[Right, 1] = new ExpressKey("Rotate Left", ExpressKeyActionType.Keystroke, vks, 2);


                    //EK3
                    vks = new VirtualKeyCode[1];
                    vks[0] = VirtualKeyCode.DELETE;
                    TabletEKs[Left, 2] = new ExpressKey("Del", ExpressKeyActionType.Keystroke, vks, 1);
				TabletEKs[Right, 2] = new ExpressKey("Del", ExpressKeyActionType.Keystroke, vks, 1);

                    //Enable Pen Rotation Selection

				    TabletEKs[Left, 3] = new ExpressKey("Pen Rotation Enable", ExpressKeyActionType.RotationMenu);
				    TabletEKs[Right, 3] = new ExpressKey("Pen Rotation Enable", ExpressKeyActionType.RotationMenu);

                    //ALT Keystroke
                    vks = new VirtualKeyCode[1];
                    vks[0]=VirtualKeyCode.MENU;
                    TabletEKs[Left,4] = new ExpressKey("Alt", ExpressKeyActionType.Keystroke, vks, 1);
				TabletEKs[Right, 4] = new ExpressKey("Alt", ExpressKeyActionType.Keystroke, vks, 1);

                    vks = new VirtualKeyCode[1];
                    vks[0] = VirtualKeyCode.CONTROL;
                    TabletEKs[Left,5] = new ExpressKey("Ctrl", ExpressKeyActionType.Keystroke, vks, 1);
				TabletEKs[Right, 5] = new ExpressKey("Ctrl", ExpressKeyActionType.Keystroke, vks, 1);


                    vks = new VirtualKeyCode[1];
                    vks[0] = VirtualKeyCode.SHIFT;
                    TabletEKs[Left,6] = new ExpressKey("Shift", ExpressKeyActionType.Keystroke, vks, 1);
				TabletEKs[Right, 6] = new ExpressKey("Shift", ExpressKeyActionType.Keystroke, vks, 1);


                    vks = new VirtualKeyCode[2];
                    vks[0] = VirtualKeyCode.CONTROL;
                    vks[1] = VirtualKeyCode.VK_Z;
                    TabletEKs[Left,7] = new ExpressKey("Undo", ExpressKeyActionType.Keystroke, vks, 2);
				TabletEKs[Right, 7] = new ExpressKey("Undo", ExpressKeyActionType.Keystroke, vks, 2);

				//Group (Circle) Button
				vks = new VirtualKeyCode[1];
				vks[0] = 0;
				TabletEKs[Left, 8] = new ExpressKey("Select Express Group", ExpressKeyActionType.ExpressGroup, vks, 0);
				TabletEKs[Right, 8] = new ExpressKey("Select Express Group", ExpressKeyActionType.ExpressGroup,vks, 0);

                    return true;

               }
          }



		public bool InitializeIntuosExpressKeys(bool loadFromFile, int NumOfExpressKeys = 8)
		{
			if (loadFromFile)
				return false;
			else
			{
				VirtualKeyCode[] vks;
				byte[] MomentaryDatar;

				//EK1
				vks = new VirtualKeyCode[2];
				vks[0] = VirtualKeyCode.CONTROL;
				vks[1] = VirtualKeyCode.F14;
				IntuosExpressKeys[ 0] = new ExpressKey("Rotate Right", ExpressKeyActionType.Keystroke, vks, 2);

				//EK2
				vks = new VirtualKeyCode[2];
				vks[0] = VirtualKeyCode.CONTROL;
				vks[1] = VirtualKeyCode.F13;
				IntuosExpressKeys[ 1] = new ExpressKey("Rotate Left", ExpressKeyActionType.Keystroke, vks, 2);

				//EK3
				vks = new VirtualKeyCode[1];
				vks[0] = VirtualKeyCode.DELETE;
				IntuosExpressKeys[ 2] = new ExpressKey("Del", ExpressKeyActionType.Keystroke, vks, 1);

				//Enable Pen Rotation Selection
				IntuosExpressKeys[3] = new ExpressKey("Pen Rotation Menu", ExpressKeyActionType.RotationMenu);

				//ALT Keystroke
				vks = new VirtualKeyCode[1];
				vks[0] = VirtualKeyCode.MENU;
				IntuosExpressKeys[ 4] = new ExpressKey("Alt", ExpressKeyActionType.Keystroke, vks, 1);

				vks = new VirtualKeyCode[1];
				vks[0] = VirtualKeyCode.CONTROL;
				IntuosExpressKeys[ 5] = new ExpressKey("Ctrl", ExpressKeyActionType.Keystroke, vks, 1);

				vks = new VirtualKeyCode[1];
				vks[0] = VirtualKeyCode.SHIFT;
				IntuosExpressKeys[ 6] = new ExpressKey("Shift", ExpressKeyActionType.Keystroke, vks, 1);

				vks = new VirtualKeyCode[2];
				vks[0] = VirtualKeyCode.CONTROL;
				vks[1] = VirtualKeyCode.VK_Z;
				IntuosExpressKeys[ 7] = new ExpressKey("Undo", ExpressKeyActionType.Keystroke, vks, 2);



				return true;
			}
		}



          bool LoadExpressKeyData ()
          {
               

               //Load in the Presets from the DB
                    
               return true;
          }


          void SaveExpressKeyData(ExpressKey[] EKArray)
          {

                    

               System.IO.File.Create("\\LocalDir");
               System.IO.FileStream myFS;

               myFS = new System.IO.FileStream("\\LocalDir", System.IO.FileMode.OpenOrCreate);

               //myFS.WriteAsync(EKArray, 0, EKArray.Length);
               for (int i = 0; i < EKArray.Length; i++)
               {
                         


               }




          }

          


     }

}
